package com.example.basicSpringBoot.bootstrap;

import com.example.basicSpringBoot.repository.MyFirstLevelRepository;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;

/**
 *
 */
@ComponentScan(basePackages = "com.example.basicSpringBoot.repository")
public class RepositoryBootstrap {
	public static void main(String[] args) {
		ConfigurableApplicationContext context =
				new SpringApplicationBuilder(RepositoryBootstrap.class)
						.web(WebApplicationType.NONE)
						.run(args);
		// 可以看到，本来扫描bean需要注解 @Component
		// 这里为什么可以扫描到当前类是因为 @Component <- @Repository <- @FirstLevelRepository <- @SecondLevelRepository
		MyFirstLevelRepository myFirstLevelRepository = context.getBean("MyFirstLevelRepository", MyFirstLevelRepository.class);
		System.out.println("myFirstLevelRepository: " + myFirstLevelRepository.toString());
		context.close();
	}
}
